﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESOL.Common;

namespace ESOL.WinUI.BaseForm
{
    public partial class frmBaseDialogyBusinessForm : frmBaseDialogyForm
    {
        #region Variable
        public ActionType ThisActionType { get; set; }
        private bool mShowSaveNewButton = false;
        public bool ShowSaveNewButton
        {
            get { return mShowSaveNewButton; }
            set { mShowSaveNewButton = value; }
        }
        private bool mShowDeleteButton = false;
        /// <summary>
        /// 显示删除按钮
        /// </summary>
        public bool ShowDeleteButton
        {
            get { return mShowDeleteButton; }
            set { mShowDeleteButton = value; }
        }
        #endregion

        #region Constructor
        public frmBaseDialogyBusinessForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Functions
        protected virtual void Click_Reject()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        protected virtual void Click_Approve()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        protected virtual void Click_Save()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        protected virtual void Click_SaveNew()
        {
        }

        protected virtual void Click_Cancel()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        protected virtual void Click_MenuItem_New()
        {
        }

        protected virtual void Click_MenuItem_Insert()
        {
        }

        protected virtual void Click_MenuItem_Delete()
        {
        }
        #endregion

        #region Event
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Click_Cancel();
        }

        private void btnReject_Click(object sender, EventArgs e)
        {
            Click_Reject();
        }

        private void btnApprove_Click(object sender, EventArgs e)
        {
            Click_Approve();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Click_Save();
        }

        protected override void OnShown(EventArgs e)
        {
            if (mShowDeleteButton)
            {
                btnReject.Visible = false;
                btnApprove.Visible = true;
                btnApprove.Text = "删除";
                if (ThisActionType == ActionType.View)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                    pnlDetail.Visible = false;
                    btnSaveNew.Visible = false;
                    btnCancel.Text = "关闭";
                    btnCancel.Image = Properties.Resources.OK;
                }
                if (mShowSaveNewButton == false)
                {
                    btnSaveNew.Enabled = false;
                }
            }
            else
            {
                if (ThisActionType == ActionType.View)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                    btnSaveNew.Visible = false;
                    btnSave.Visible = false;
                    btnCancel.Text = "关闭";
                    btnCancel.Image = Properties.Resources.OK;
                }
                else if (ThisActionType == ActionType.New)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                }
                else if (ThisActionType == ActionType.Modify)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                }
                else if (ThisActionType == ActionType.Expense)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                    btnSaveNew.Visible = false;
                    pnlDetail.Text = "付款";
                }
                else if (ThisActionType == ActionType.Approve)
                {
                    pnlDetail.Enabled = true;
                    btnSave.Enabled = false;
                    btnSaveNew.Enabled = false;
                }
                else if (ThisActionType == ActionType.MakeOrder)
                {
                    btnReject.Visible = false;
                    btnApprove.Visible = false;
                }
                else if (ThisActionType == ActionType.CEOApprove)
                {
                    pnlDetail.Enabled = false;
                    btnSaveNew.Enabled = false;
                }
                else if (ThisActionType == ActionType.Confirm)
                {
                    pnlDetail.Enabled = false;
                    btnSaveNew.Enabled = false;
                    btnReject.Visible = false;
                    btnApprove.Text = "确认";
                }
                if (mShowSaveNewButton == false)
                {
                    btnSaveNew.Enabled = false;
                }
            }
            if (ThisActionType == ActionType.View && (this.Tag == null || this.Tag.ToString() != "Enable"))
            {
                UICommon.UICommonFunctions.SetControlsEnable(pnlTop.Controls, false);
            }
            base.OnShown(e);
        }

        private void tsmiNew_Click(object sender, EventArgs e)
        {
            Click_MenuItem_New();
        }

        private void tsmiInsert_Click(object sender, EventArgs e)
        {
            Click_MenuItem_Insert();
        }

        private void tsmiDelete_Click(object sender, EventArgs e)
        {
            Click_MenuItem_Delete();
        }

        private void btnSaveNew_Click(object sender, EventArgs e)
        {
            Click_SaveNew();
        }
        #endregion
    }
}
